Skip to content

Conversation

@Turdot
Copy link

@Turdot Turdot commented Jan 7, 2026

Summary

Fixes #3101

Chart plugins (Y Line, Y Bar, Y Area, X Bar, etc.) crash when used inside <perspective-workspace> with the error:

Cannot read properties of null (reading 'opacity')
TypeError: Cannot read properties of null (reading 'opacity')
    at colorStyles.ts:63:26

Root Cause

The workspace theme files (pro.less and pro-dark.less) were missing the d3fc CSS variable definitions. The perspective-viewer themes include @include perspective-viewer-pro--d3fc which defines variables like --d3fc-series, but the workspace themes only included perspective-viewer-pro--colors.

When colorStyles.ts tries to read --d3fc-series via getComputedStyle(), it gets an empty string, which causes d3.color(null) to return null, and accessing .opacity on null throws the error.

Changes

  1. packages/workspace/src/themes/pro.less: Add @include perspective-viewer-pro--d3fc
  2. packages/workspace/src/themes/pro-dark.less: Add @include perspective-viewer-pro-dark--d3fc
  3. packages/viewer-d3fc/src/ts/series/colorStyles.ts: Add defensive null check in getOpacityFromColor() as additional protection

Testing

Before fix: Charts crash immediately when rendering in workspace
After fix: Charts render correctly with proper colors

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • I have read the CONTRIBUTING document

Fixes perspective-dev#3101

Chart plugins (Y Line, Y Bar, Y Area, etc.) crash in perspective-workspace
with error 'Cannot read properties of null (reading opacity)'.

Root cause: workspace theme files were missing the d3fc CSS variable
definitions (@include perspective-viewer-pro--d3fc mixin), causing
--d3fc-series and related variables to be undefined.

Changes:
- Add @include perspective-viewer-pro--d3fc to pro.less
- Add @include perspective-viewer-pro-dark--d3fc to pro-dark.less
- Add defensive null check in getOpacityFromColor() as additional protection

Signed-off-by: Yanpeng Wang <[email protected]>
@Turdot Turdot force-pushed the fix/workspace-d3fc-css-variables branch from caf2294 to d42829d Compare January 7, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Does perspective-python support multi-pane workspace with chart plugins?

1 participant